import java.util.Arrays;

/**
 * @author SaoE
 * @date 2025/3/3 17:02
 */
public class _322 {
    public int coinChange(int[] coins, int amount) {
        Arrays.sort(coins);
        int[] dp = new int[amount + 1];
        Arrays.fill(dp, 999);
        dp[0] = 0;
        for (int i = 1; i <= amount; i++){
            for (int j = coins.length - 1; j >= 0; j--){
                if (i - coins[j] >= 0){
                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
                }
            }
        }
        return dp[amount]==999 ? -1 : dp[amount];
    }
}
